package com.fizzkai.p2p.website.controller;

import com.fizzkai.p2p.core.domain.UserInfo;
import com.fizzkai.p2p.core.service.ISystemDictionaryItemService;
import com.fizzkai.p2p.core.service.IUserInfoService;
import com.fizzkai.p2p.core.util.AjaxResult;
import com.fizzkai.p2p.website.util.RequireLogin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class BasicInfoController {

    @Autowired
    private IUserInfoService userInfoService;
    @Autowired
    private ISystemDictionaryItemService dictionaryItemService;

    @RequestMapping("/basicInfo")
    @RequireLogin
    // 个人 资料的 页面
    public String basicInfo(Model model){
        // 查出页面 需要的 内容
        model.addAttribute("userInfo", userInfoService.getCurrent());
        model.addAttribute("incomeGrades", dictionaryItemService.queryListByParentSn("incomeGrade"));
        model.addAttribute("educationBackgrounds", dictionaryItemService.queryListByParentSn("educationBackground"));
        model.addAttribute("marriages", dictionaryItemService.queryListByParentSn("marriage"));
        model.addAttribute("kidCounts", dictionaryItemService.queryListByParentSn("kidCount"));
        model.addAttribute("houseConditions", dictionaryItemService.queryListByParentSn("houseCondition"));
        return "basicInfo";
    }

    // 保存个人资料
    @RequestMapping("/basicInfo_save")
    @ResponseBody
    public Object basicInfo_save(UserInfo userInfo) {
        userInfoService.basicInfoSave(userInfo);
        return new AjaxResult("保存成功");
    }
}
